<template>
	<view class="liwuall" name="liwu">
		
		<view class="flexbc" >
			<!-- <view class="flexci" v-if="checkren">
				<view>赠送给：</view>
				<view class="flexci who" >
					<view><image :src="checkren.head_img"></image></view>
					<view>{{checkren.username}}</view>
				</view>
			</view> -->
			
			<view class="lf flexci">
				<view class="flex yue">
					<view><image src="../../../static/assets/img/t5.png"></image></view>
					<view style="border-right: 1px #8EFFED solid; width: 100rpx; margin-right: 20rpx;">{{yue.balance}}</view>
				</view>
				<view class="chong" @click="chongzhi">充值></view>
			</view>
			<!-- <view>最近赠送：</view>
			<view class="flexci who" v-for="item in 2" :key="item">
				<view><image src="../../../static/assets/img/tx1.png"></image></view>
				<view>赵家驹</view>
			</view> -->
		</view>
		<!-- <view class="flexci sr">
			<u-input placeholder="输入赠送人的姓名或号码牌" @input="getren" @search="getren" v-model="sear.name">
				<template slot="suffix"  >
					<image src="../../../static/assets/img/sousuo.png" style="width: 33rpx; height: 33rpx;" @click="getren" >
				</template>
			</u-input>
		</view> -->
		<!-- <view class="flexci" style="flex-wrap: wrap;">
			<view class="flexci lis" v-for="item in listren" :key="item.id" @click="xuanzeren(item)">
				<view><image :src="item.head_img"></image></view>
				<view>{{item.username}}_{{item.no}}</view>
			</view>
		</view> -->
		<view class="liwu flexci">
			<view class="liwuli" :class="check_id == item.id?'liwuact':''" v-for="item in list" :key="item.id" @click="check_id = item.id">
				<view class="flexcc"><image :src="item.img"></image></view>
				<view class="flexcc">{{item.price}}派币</view>
				<view class="flexcc" v-if="check_id != item.id">{{item.name}}</view>
				<view class="flexcc zengsong" v-if="check_id == item.id" @click="songliwu(item.id,item)">赠送</view>
			</view>
		</view>

		<u-toast ref="uToast2"></u-toast>
	</view>
</template>

<script>
	export default {
		name:"liwu",
		props:['liwuid','sign_id'],
		data() {
			return {
				list:"",
				checkren:"",
				check_id:"",
				receiver_id:3,
				player_id:"",
				sear:{
					game_id: uni.getStorageSync('activity_id'),
					user_id: JSON.parse(uni.getStorageSync('person')).id,
					name: "",
					sign_id:"",
					page:1,
					page_size:10,
					//package_id:uni.getStorageSync('pack_id')
				},
				listren:"",
				yue:""
			}
		},
		mounted() {
			
			this.getlist()
			this.getren()
			this.getyue()
			if(this.checkren == ''){
				if(uni.getStorageSync('checkren')){
					this.checkren = JSON.parse(uni.getStorageSync('checkren'))
				}
			}
		},
		onLoad() {
			uni.$u.http.get(this.urlass + '/api/position/position/allliveuser', {
				params: this.sear
			}).then(res => {
				this.listren = res.data.data.data
			})	
		},
		methods: {
			getyue:function(){
				uni.$u.http.get(this.urlass + '/api/v1/users/account',{
					params:{
						token: uni.getStorageSync('token')
					}
				}).then(res => {
					this.yue = res.data.data
				})
			},
			chongzhi:function(){
			     this.$emit('chongzhi')	
			},
			xuanzeren:function(item){
				this.checkren = item
				uni.setStorageSync('checkren',JSON.stringify(this.checkren))
			},
			songliwu:function(id,item){
				
				if(this.checkren == ''){
					this.$refs.uToast2.show({
						message:'请选择赠送的选手',
						type:"error"
					})
					return false
				}
				console.log(this.checkren)
				let datax = {
					gift:{
						gift_img: item.img,
						gift_name: item.name,
						head_img: this.checkren.head_img,
						player_name: this.checkren.nickname || this.checkren.username
					}
				}
				this.$emit('wosongliwu',datax)
				
				uni.$u.http.post(this.urlass + '/api/v1/talk/message/gift', {
					activity_id:uni.getStorageSync('activity_id'),
					receiver_id:this.receiver_id,
					talk_type:2,
					gift_id:id,
					player_id:this.checkren.id,
					player_name:this.checkren.username,
					token:uni.getStorageSync('token'),
					// package_id:uni.getStorageSync('pack_id')
				}).then(res2 => {
					if (res2.data.code == 200) {
						this.getyue()
					}else{
						this.$refs.uToast2.show({
							message: res.data.msg.info,
							type:"error"
						})
					}
				}).catch(err=>{
					this.$refs.uToast2.show({
						message:err.data.error,
						type:"error"
					})
				})
			},
			getlist:function(){
				uni.$u.http.get(this.urlass + '/api/v1/group/gift/list', {
					params: {
						token:uni.getStorageSync('token')
					},
				}).then(res => {
					this.list = res.data.data.rows
					this.list.forEach(item=>{
						item.price = parseInt(item.price)
					})
					this.check_id = this.list[0].id
				})
			},
			//获取人的位置
			getren:function() {
				console.log(1)
				if(this.sign_id){
					this.sear.sign_id = this.sign_id
				}
				uni.$u.http.get(this.urlass + '/api/position/position/allliveuser', {params: this.sear}).then(res => {
					this.listren = res.data.data.data
					
					if(this.sign_id && this.listren != ''){
						this.listren.forEach(item=>{
					
							if(item.id == this.sign_id){
								this.checkren = item
								uni.setStorageSync('checkren',JSON.stringify(this.checkren))
								console.log(this.checkren)
							}
						})
					}
					
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.liwuall { padding:30rpx; background: #171717; color:#FFFFFF; border-radius: 20rpx 20rpx 0 0;
		
		.who{ border:1px #8EFFED solid; padding:10rpx 10rpx; border-radius:40rpx; margin-right: 10rpx;
			image{ width: 42rpx; height:42rpx; border-radius:21rpx; margin-right: 10rpx;}
		}
		.lf{ border:1px #8EFFED solid; padding:15rpx 20rpx; border-radius:40rpx;
			image{ width: 36rpx; height:36rpx; border-radius:18rpx; margin-right: 10rpx;}
		}
		.rf{
			.chongzhi{ background: #8EFFED; color: #00308D; padding:17rpx 30rpx; border-radius:40rpx;}
		}
		
		.lis{ background: rgba(255,255,255,0.1); padding:10rpx 20rpx; margin-right: 20rpx; margin-top: 20rpx; border-radius: 10rpx;
			
			image{ width: 42rpx; height:42rpx; border-radius:21rpx; margin-right: 10rpx;}
		}
		
		.liwu{ flex-wrap: wrap;  margin-top: 20rpx;
			.liwuli{ width: 25%; padding: 20rpx 0 0;  overflow: hidden;
				image{ width: 98rpx; height:98rpx; margin-bottom: 10rpx; }
			}
			.liwuact{border:2px #8EFFED solid; border-radius:27rpx;}
			.zengsong{ padding: 10rpx 0; margin-top: 20rpx; background: #8EFFED; color:#000000;  border-radius:27rpx 27rpx 0 0;}
		}
		
		.sr {
			background: rgba(255,255,255,0.1);
			height: 67rpx;
			padding: 0 30rpx;
			border-radius: 2rpx;
			border-radius: 67rpx; margin-top: 20rpx;
		}
		
	}
</style>
